package com.sg.business.commons.labelprovider.workd;

import java.util.List;

import org.bson.types.ObjectId;

import com.mobnut.db.model.ModelService;
import com.mobnut.db.model.PrimaryObject;
import com.sg.business.model.DeliverableDefinition;
import com.sg.business.model.DocumentDefinition;
import com.sg.business.model.WorkDefinition;
import com.sg.widgets.commons.labelprovider.ConfiguratorColumnLabelProvider;

public class WorkDefinitionLabelProvider extends
		ConfiguratorColumnLabelProvider {

	@Override
	public String getText(Object element) {
		if (element instanceof DocumentDefinition) {
			String str = "";
			DocumentDefinition docd = (DocumentDefinition) element;
			List<PrimaryObject> deliverableDefList = docd
					.getDeliverableDefinition();
			for (PrimaryObject primaryObject : deliverableDefList) {
				Object workdObject = primaryObject
						.getValue(DeliverableDefinition.F_WORK_DEFINITION_ID);
				WorkDefinition workd = ModelService.createModelObject(
						WorkDefinition.class, (ObjectId) workdObject);
				String workdText = workd.getDesc();
				if (str.indexOf(workdText) == -1) {
					if(str != ""){
						str += ",";
					}
					str += workdText;
				}
			}
			return str;
		}
		return "";
	}
}
